package asteroids.model.programs.parsing.statements;

import java.util.List;
import java.util.Map;

import be.kuleuven.cs.som.annotate.Basic;

import asteroids.model.Ship;
import asteroids.model.programs.parsing.expressions.Expression;
import asteroids.model.programs.parsing.types.*;

/**
 * A class of turn statements.
 * A turn statement makes the ship that executes the program turn a given angle.
 * 
 * @author Thijs Dieltjens - Wim Konings
 * @version 2.0
 */
public class Turn extends Action {

	public Turn (Expression angle,int line, int column){
		super(line,column);
		this.angle =angle;
	}

	@Basic
	public Expression getAngle() {
		return angle;
	}

	private Expression angle;

	@Override
	public void execute(Ship ship) {
		double angleToTurn =Ship.correctAngle(((DoubleLiteral) getAngle().eval(ship, null)).getValue());
		ship.turn(angleToTurn);
	}

	@Override
	public List<String> getTypeCheckErrors(List<String> errors, Map<String, Type> globals) {
		if(getAngle().eval(null, globals).getClass()!=DoubleLiteral.class){
			errors.add(getLine()+"-"+getColumn()+": No valid angle given to turn.");
		}
		return errors;
	}

}
